<template>
  <div v-loading="loading" class="parentStyle">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('项目名称')" prop="dealName">
            <el-input v-model="form.dealName" :placeholder="$t('项目名称')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('融资类型')" prop="financingType">
            <el-select v-model="form.financingType" :placeholder="$t('融资类型')" clearable @change="financingTypeChange()">
              <el-option
                v-for="dict in financingTypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('预计融资金额') + $t('金额单位')" prop="estimatedFinancingAmount">
            <Money v-model="form.estimatedFinancingAmount" unit="w" :placeholder="$t('预计融资金额')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item v-if="form.financingType === 'YHDK'" :label="$t('银行名称')" prop="bankId">
            <el-select v-model="form.bankId" :placeholder="$t('银行名称')" filterable clearable>
              <el-option
                v-for="item in dealBankListList"
                :key="item.id"
                :label="$t(item.bankName)"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item v-if="form.financingType === 'YHDK'" :label="$t('利率模式')" prop="interestRatePattern">
            <el-select v-model="form.interestRatePattern" :placeholder="$t('利率模式')" clearable @change="interestRatePatternChange()">
              <el-option
                v-for="dict in interestRatePatternOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item v-if="form.financingType === 'YHDK' && form.interestRatePattern === 'FD'" :label="$t('上浮利率(%)')" prop="floatingInterestRate">
            <Ratio
              v-model="form.floatingInterestRate"
              :precision="4"
              :controls="false"
              :min="0"
              :max="100"
              :placeholder="$t('上浮利率(%)')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item v-if="form.financingType === 'YHDK' && form.interestRatePattern === 'FD'" :label="$t('基准利率(%)')" prop="benchmarkInterestRate">
            <div style="display: flex;">
              <Ratio
                v-model="form.benchmarkInterestRate"
                :precision="4"
                :controls="false"
                :min="0"
                :max="100"
                :placeholder="$t('基准利率(%)')"
              />
              <el-button slot="append" type="primary" @click="reminderTasks(form)">{{ $t('定时任务') }}</el-button>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item v-if="form.financingType === 'YHDK' && form.interestRatePattern === 'FD'" :label="$t('利率(%)')" prop="interestRate">
            <Ratio
              v-model="form.interestRate"
              :precision="4"
              :controls="false"
              :min="0"
              :max="200"
              disabled
              :placeholder="$t('利率(%)')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item v-if="form.financingType === 'NBJK' || form.financingType === 'FHZQ' || form.financingType === 'YHDK' && form.interestRatePattern === 'GD'" :label="$t('利率(%)')" prop="interestRateBank">
            <Ratio
              v-model="form.interestRate"
              :precision="4"
              :controls="false"
              :min="0"
              :max="100"
              :placeholder="$t('利率(%)')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item v-if="form.financingType === 'YHDK'" :label="$t('融资摘要')" prop="financingSummary">
            <el-input v-model="form.financingSummary" type="textarea" :placeholder="$t('融资摘要')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item v-if="form.financingType === 'YHDK'" :label="$t('担保方式')" prop="guaranteeMethod">
            <el-input v-model="form.guaranteeMethod" type="textarea" :placeholder="$t('担保方式')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
      </el-row>
      <div v-if="form.financingType === 'FHZQ'">
        <!--募集明细-->
        <div class="area-header">
          <span class="area-header-title">{{ $t('募集明细') }}</span>
        </div>
        <el-table :data="form.dealBaseFinancingRaises" border class="nowrapTable formTable">
          <el-table-column :label="$t('档位')" align="center">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('档位') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'dealBaseFinancingRaises.' + scope.$index + '.gear'" :rules="dealBaseFinancingRaisesRules.gear">

                <el-input v-model="scope.row.gear" :placeholder="$t('档位')" show-word-limit maxlength="100" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('投资机构')" align="center">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('投资机构') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'dealBaseFinancingRaises.' + scope.$index + '.investmentInstitution'" :rules="dealBaseFinancingRaisesRules.investmentInstitution">
                <el-input v-model="scope.row.investmentInstitution" :placeholder="$t('投资机构')" show-word-limit maxlength="100" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('投资金额（万）')" align="center">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('投资金额（万）') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'dealBaseFinancingRaises.' + scope.$index + '.investmentAmount'" :rules="dealBaseFinancingRaisesRules.investmentAmount">
                <Money v-model="scope.row.investmentAmount" unit="w" :placeholder="$t('投资金额（万）')" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('备注')" align="center">
            <template slot="header" slot-scope="{}">
              <span>{{ $t('备注') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'dealBaseFinancingRaises.' + scope.$index + '.remark'" :rules="dealBaseFinancingRaisesRules.remark">
                <el-input v-model="scope.row.remark" :placeholder="$t('备注')" show-word-limit maxlength="2000" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column v-if="!otherBtnHide" :label="$t('操作')" align="center" width="60px">
            <template slot-scope="scope">
              <el-button v-hasPermi="['financing:base:remove']" size="small" type="text" icon="el-icon-delete" @click="delRaisesHandle(scope.$index, scope.row)" />
            </template>
          </el-table-column>
        </el-table>
        <div v-if="!otherBtnHide" class="tol">
          <el-button v-hasPermi="['financing:base:edit']" type="primary" icon="el-icon-plus" size="mini" @click="addRaises">{{ $t('添加明细') }}</el-button>
        </div>
        <!--档位明细-->
        <div class="area-header">
          <span class="area-header-title">{{ $t('档位明细') }}</span>
        </div>
        <el-table :data="form.dealBaseFinancingGears" border class="nowrapTable formTable">
          <el-table-column :label="$t('档位')" align="center">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('档位') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'dealBaseFinancingGears.' + scope.$index + '.gear'" :rules="dealBaseFinancingGearsRules.gear">

                <el-input v-model="scope.row.gear" :placeholder="$t('档位')" show-word-limit maxlength="100" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('发行金额')" align="center">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('发行金额（万）') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'dealBaseFinancingGears.' + scope.$index + '.issueAmount'" :rules="dealBaseFinancingGearsRules.issueAmount">
                <Money v-model="scope.row.issueAmount" unit="w" :placeholder="$t('发行金额（万）')" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('融资余额（万）')" align="center">
            <template slot="header" slot-scope="{}">
              <span>{{ $t('融资余额（万）') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'dealBaseFinancingGears.' + scope.$index + '.financingBalance'" :rules="dealBaseFinancingGearsRules.financingBalance">
                <Money v-model="scope.row.financingBalance" unit="w" :placeholder="$t('融资余额（万）')" />
              </el-form-item>
            </template>
          </el-table-column>

          <el-table-column :label="$t('票面利率（%）')" align="center">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('票面利率（%）') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'dealBaseFinancingGears.' + scope.$index + '.couponRate'" :rules="dealBaseFinancingGearsRules.couponRate">
                <Ratio
                  v-model="scope.row.couponRate"
                  :precision="4"
                  :controls="false"
                  :min="0"
                  :max="100"
                  :placeholder="$t('票面利率(%)')"
                />
              </el-form-item>
            </template>
          </el-table-column>

          <el-table-column :label="$t('发行日期')" align="center">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('发行日期') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'dealBaseFinancingGears.' + scope.$index + '.issueDate'" :rules="dealBaseFinancingGearsRules.issueDate">
                <el-date-picker
                  v-model="scope.row.issueDate"
                  clearable
                  style="width: 200px"
                  type="date"
                  value-format="yyyy-MM-dd"
                  :placeholder="$t('发行日期')"
                />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('到期日期')" align="center">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('到期日期') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'dealBaseFinancingGears.' + scope.$index + '.expiryDate'" :rules="dealBaseFinancingGearsRules.expiryDate">
                <el-date-picker
                  v-model="scope.row.expiryDate"
                  clearable
                  style="width: 200px"
                  type="date"
                  value-format="yyyy-MM-dd"
                  :placeholder="$t('到期日期')"
                />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('备注')" align="center">
            <template slot="header" slot-scope="{}">
              <span>{{ $t('备注') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="'dealBaseFinancingGears.' + scope.$index + '.remark'" :rules="dealBaseFinancingGearsRules.remark">
                <el-input v-model="scope.row.remark" :placeholder="$t('备注')" show-word-limit maxlength="2000" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column v-if="!otherBtnHide" :label="$t('操作')" align="center" width="60px">
            <template slot-scope="scope">
              <el-button v-hasPermi="['financing:base:remove']" size="small" type="text" icon="el-icon-delete" @click="delGearsHandle(scope.$index, scope.row)" />
            </template>
          </el-table-column>v
        </el-table>
        <div v-if="!otherBtnHide" class="tol">
          <el-button v-hasPermi="['financing:base:edit']" type="primary" icon="el-icon-plus" size="mini" @click="addGears">{{ $t('添加明细') }}</el-button>
        </div>
      </div>
      <FileTable :list.sync="form.fileList" has-permi="financing:base" data-type="deal_base_financing" :business-id="form.dealId" :btn-show="!otherBtnHide" />
    </el-form>
    <div slot="footer" class="dialog-footer">
      <!--保存 取消按钮-->
      <save-btn has-permi="financing:base" :cancel-show="!this.$route.query.id" />
    </div>

    <!-- LPR利率提醒 -->
    <el-dialog :title="$t('LPR利率提醒')" :visible="reminderOpen" :close-on-click-modal="false" :lock-scroll="false" append-to-body @close="reminderOpen = false">
      <div v-loading="reminderLoading">
        <el-form ref="form" :model="remindForm" :rules="rules" label-width="120px" class="dataForm">
          <el-row>
            <el-col :span="12">
              <el-form-item :label="$t('提醒人')" prop="remindUserId">
                <UserSelect
                  v-model="remindForm.remindUserId"
                  :multiple="true"
                  fund-invest
                  :placeholder="$t('提醒人')"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('提醒频率')" prop="reminderFrequency">
                <el-radio-group v-model="remindForm.reminderFrequency">
                  <el-radio
                    v-for="dict in reminderFrequencyOptions"
                    :key="dict.dictValue"
                    :label="dict.dictValue"
                  >{{ $t(dict.dictLabel) }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col v-if="remindForm.reminderFrequency === 'TIMER'" :span="12">
              <el-form-item :label="$t('定时提醒时间')" prop="remindTime">
                <el-date-picker
                  v-model="remindForm.remindTime"
                  clearable
                  style="width: 200px"
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  format="yyyy-MM-dd HH:mm"
                  :placeholder="$t('定时提醒时间')"
                />
              </el-form-item>
            </el-col>
            <el-col v-else :span="24">
              <el-form-item :label="$t('频率提醒表达式')" prop="cron">
                <Cron v-model="remindForm.cron" :cron-value.sync="remindForm.frequencyCronValue" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('提醒状态')" prop="status">
                <el-switch
                  v-model="remindForm.status"
                  active-color="#13ce66"
                  inactive-color="#ff4949"
                  :active-text="$t('开启')"
                  :inactive-text="$t('关闭')"
                  :active-value="1"
                  :inactive-value="0"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align: right;">
        <el-button @click="cancelReminder">{{ $t("取消") }}</el-button>
        <el-button type="primary" @click="saveReminder">{{ $t("保存") }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  saveDealBaseFinancing,
  getDealBaseFinancing,
  delDealBaseFinancingGear, delDealBaseFinancingRaise, interestRateCalculation, listDealBaseFinancing
} from '@/api/deal/financing/base/dealBaseFinancing'
import { listDealBankList } from '@/api/deal/financingLease/dealBank/dealBankList'
import Cron from '@/components/Cron'
    export default {
        components: {
          Cron
        },
        data() {
          var checkCertificateNumber = (rule, value, callback) => {
              console.info(this.form)
              if (value === '' || value === undefined || value == null) {
                callback(new Error('必填信息'))
              } else {
                this.dealBaseFinancingList.forEach(item => {
                  if (this.form.id !== item.id) {
                    if (this.form.dealName === item.dealName) {
                      callback(new Error('名称重复'))
                    }
                  }
                })
                callback()
              }
            }
            return {
                // 表单参数
                form: {
                  dealBaseFinancingGears: [],
                  dealBaseFinancingRaises: []
                },
                remindForm: {
                  remindUserId: [],
                  reminderFrequency: undefined,
                  remindTime: undefined,
                  cron: undefined,
                  status: undefined
                },
                dealBankListList: [],
                dealBaseFinancingList: [],
                // 提醒频率字典
                reminderFrequencyOptions: [],
                // 融资类型字典
                financingTypeOptions: [],
                // 利率模式字典
                interestRatePatternOptions: [],
                gear: 0,
                // 遮罩层
                loading: false,
                reminderLoading: false,
                // 定时任务
                reminderOpen: false,
                // 表单校验
                rules: {
                  dealName: [{ required: true, validator: checkCertificateNumber, trigger: 'blur' }],
                  financingType: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  estimatedFinancingAmount: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  bankId: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  interestRatePattern: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  floatingInterestRate: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  benchmarkInterestRate: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  interestRate: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
                },
                dealBaseFinancingGearsRules: {
                  issueAmount: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  couponRate: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  issueDate: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  expiryDate: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
                },
                dealBaseFinancingRaisesRules: {
                  gear: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  investmentInstitution: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  investmentAmount: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
                },
                // 是否隐藏其它按钮
                otherBtnHide: false
            }
        },
        computed: {
          newList() {
            return JSON.parse(JSON.stringify(this.form.dealBaseFinancingRaises))
          }
        },
        watch: {
          'form.floatingInterestRate': {
            handler(newValue) {
              if (newValue !== '' && newValue !== undefined) {
                this.interestRateCalculation(this.form)
              }
            },
            immediate: true
          },
          'form.benchmarkInterestRate': {
            handler(newValue) {
              if (newValue !== '' && newValue !== undefined) {
                this.interestRateCalculation(this.form)
              }
            },
            immediate: true
          },
          'form.dealBaseFinancingRaises': {
            handler(newVal) {
              // console.log(newVal)
              this.listAdd(newVal)
            },
            deep: true
          }
        },
        created() {
            this.getDicts('deal_financing_type').then(response => {
                this.financingTypeOptions = response.data
            })
            this.getDicts('interest_rate_pattern').then(response => {
                this.interestRatePatternOptions = response.data
            })
            this.getDicts('reminder_frequency').then(response => {
              this.reminderFrequencyOptions = response.data
            })
            listDealBankList({}).then(response => {
              this.dealBankListList = response.rows
            })
        },
        mounted() {
          this.$bus.$emit('async_done')
        },
        methods: {
            listDealBaseFinancing() {
              listDealBaseFinancing({}).then(response => {
                this.dealBaseFinancingList = response.rows
              })
            },
            // 初始化数据
            init(data) {
                this.loading = true
                if (data != null && data.id !== undefined) {
                    getDealBaseFinancing(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    }).catch(() => {
                      this.loading = false
                    })
                } else {
                    this.reset()
                    this.loading = false
                }
                this.listDealBaseFinancing()
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    dealName: undefined,
                    financingType: undefined,
                    estimatedFinancingAmount: undefined,
                    interestRate: undefined,
                    bankId: undefined,
                    interestRatePattern: undefined,
                    floatingInterestRate: undefined,
                    benchmarkInterestRate: undefined,
                    financingSummary: undefined,
                    guaranteeMethod: undefined,
                    remindUserId: [],
                    reminderFrequency: 'TIMER',
                    remindTime: undefined,
                    cron: undefined,
                    status: 0,
                    remark: undefined,
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined,
                    delFlag: undefined,
                    dealBaseFinancingGears: [],
                    dealBaseFinancingRaises: []
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            cancelRemindForm() {

            },
            /** 提交按钮 */
            submitForm() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveDealBaseFinancing(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                }).catch(() => {
                    this.loading = false
                })
           },
          // 删除募集明细
          delGearsHandle(index, row) {
            const id = row.id
            if (id !== undefined && id !== '' && id != null) {
              this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
                confirmButtonText: this.$t('确定'),
                cancelButtonText: this.$t('取消'),
                type: 'warning'
              }).then(function() {
                  return delDealBaseFinancingGear(id)
                }).then(() => {
                this.form.dealBaseFinancingGears.splice(index, 1)
                return this.msgSuccess(this.$t('删除成功'))
              }).catch(function() {})
            } else {
              this.form.dealBaseFinancingGears.splice(index, 1)
            }
          },
          // 删除档位明细
          delRaisesHandle(index, row) {
            const id = row.id
            if (id !== undefined && id !== '' && id != null) {
              this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
                confirmButtonText: this.$t('确定'),
                cancelButtonText: this.$t('取消'),
                type: 'warning'
              }).then(function() {
                  return delDealBaseFinancingRaise(id)
                }).then(() => {
                this.form.dealBaseFinancingRaises.splice(index, 1)
                return this.msgSuccess(this.$t('删除成功'))
              }).catch(function() {})
            } else {
              this.form.dealBaseFinancingRaises.splice(index, 1)
            }
          },
          // 募集明细
          addGears() {
            const row = {
              id: undefined,
              financingId: undefined,
              gear: '',
              issueAmount: '',
              financingBalance: '',
              couponRate: '',
              issueDate: '',
              expiryDate: '',
              remark: ''
            }
            if (!(this.form.dealBaseFinancingGears instanceof Array)) {
              this.$set(this.form, 'dealBaseFinancingGears', [])
            }
            this.$nextTick(() => {
              this.form.dealBaseFinancingGears.push(row)
            })
          },
          // 档位明细
          addRaises() {
            const row = {
              id: undefined,
              financingId: undefined,
              gear: '',
              investmentInstitution: '',
              investmentAmount: '',
              remark: ''
            }
            if (!(this.form.dealBaseFinancingRaises instanceof Array)) {
              this.$set(this.form, 'dealBaseFinancingRaises', [])
            }
            this.$nextTick(() => {
              this.form.dealBaseFinancingRaises.push(row)
              this.addGears()
            })
          },
          // 期限计算
          interestRateCalculation(data) {
            interestRateCalculation(data).then(response => {
              console.log(response.data)
              this.form.interestRate = response.data.interestRate
            })
          },
          listAdd(newVal) {
            newVal = this.filterList(newVal)
            console.log(newVal)
            for (var i = 0; i < newVal.length; i++) {
              this.form.dealBaseFinancingGears[i].gear = newVal[i].gear
              this.form.dealBaseFinancingGears[i].issueAmount = 0
              this.form.dealBaseFinancingRaises.forEach(raises => {
                if (raises.gear === newVal[i].gear && raises.investmentAmount !== undefined) {
                  this.form.dealBaseFinancingGears[i].issueAmount += raises.investmentAmount
                }
              })
            }
            for (var j = 0; j < this.form.dealBaseFinancingGears.length; j++) {
              if (this.form.dealBaseFinancingGears[j].gear === '' || this.form.dealBaseFinancingGears[j].gear === undefined) {
                this.form.dealBaseFinancingGears.splice(j, 1)
              }
            }
          },
          filterList(arr) {
            const res = new Map()
            return arr.filter(arr => !res.has(arr.gear) && res.set(arr.gear, arr.gear))
          },
          financingTypeChange() {
            this.form.dealBaseFinancingGears = []
            this.form.dealBaseFinancingRaises = []
            this.form.bankId = undefined
            this.form.interestRatePattern = undefined
            this.form.floatingInterestRate = undefined
            this.form.benchmarkInterestRate = undefined
            this.form.interestRate = undefined
            this.form.financingSummary = undefined
            this.form.guaranteeMethod = undefined
          },
          interestRatePatternChange() {
            this.form.floatingInterestRate = undefined
            this.form.benchmarkInterestRate = undefined
            this.form.interestRate = undefined
          },
          reminderTasks() {
            this.reminderOpen = true
            this.remindForm.remindUserId = this.form.remindUserId
            this.remindForm.reminderFrequency = this.form.reminderFrequency
            this.remindForm.remindTime = this.form.remindTime
            this.remindForm.cron = this.form.cron
            this.remindForm.status = this.form.status
          },
          saveReminder() {
            this.form.remindUserId = this.remindForm.remindUserId
            this.form.reminderFrequency = this.remindForm.reminderFrequency
            this.form.remindTime = this.remindForm.remindTime
            this.form.cron = this.remindForm.cron
            this.form.status = this.remindForm.status
            this.msgSuccess(this.$t('添加成功'))
            this.reminderOpen = false
          },
          cancelReminder() {
            this.reminderOpen = false
          }

        }
    }
</script>
